package priv.lirenhe.dissertation.executor;

import java.text.ParseException;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import priv.lirenhe.dissertation.service.impl.WebPageServiceImpl;
import priv.lirenhe.dissertation.service.impl.WebUrlServiceImpl;

public class InMysqlDB {
	
	private static WebUrlServiceImpl webUrlServiceImpl = null;
	private static WebPageServiceImpl webPageServiceImpl = null;
	static{
		if(webUrlServiceImpl == null || webPageServiceImpl == null){
			ApplicationContext ac = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml","mybatis-config.xml"});
			webUrlServiceImpl = (WebUrlServiceImpl) ac.getBean("WebUrlServiceImpl");
			
			webPageServiceImpl = (WebPageServiceImpl) ac.getBean("WebPageServiceImpl");
		}
	}
	
	public static void putDataInMysqlDB(Map<String,Map<String,String>> webUrlMap,Map<String,String> webPageMap){
		try {
			System.out.println("入库webUrlMap=====");
			int i = 0;
			i = webUrlServiceImpl.insertUrlSelective(webUrlMap);
			if(i>=0){
				System.out.println("清空webUrlMap=====");
				webUrlMap.clear();
			}
			
			//内容入库
			System.out.println("内容入库webPageMap======");
			int x = 0;
			x = webPageServiceImpl.insertPageSelective(webPageMap);
			if(x >= 0){
				webPageMap.clear();
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

}
